package stream.Demo06;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @Author Miku
 * @Create 2021/4/30 9:09
 * 使用ObjectOutStream实现对象的序列化
 * 要求:序列化的类必须要实现Serializable接口
 */
public class Test {
    public static void main(String[] args) throws IOException {
        //1.创建对象流
        FileOutputStream fos = new FileOutputStream("e:\\stu.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        //2.序列化(写入操作)
        Student miku = new Student("miku", 16);
        oos.writeObject(miku);
        //3.关闭
        oos.close();
        System.out.println("序列化完毕");
    }
}
